<template>
<div class="job-info">
    <el-row type="flex" justify="end">
        <el-tooltip content="打印个人基本信息">
            <router-link :to="`/employees/myPrint/${userId}?type=job`">
                <i class="el-icon-printer" style="font-size: 20px; color: #2784fb;" />
            </router-link>
        </el-tooltip>
    </el-row>
    <!-- 基础信息 -->
    <el-form label-width="140px">
        <div class="block">
            <div class="title">基础信息</div>
            <el-form-item label="岗位">
                <el-input v-model="formData.post" placeholder="请输入" />
            </el-form-item>
            <!-- <el-form-item label="转正日期">
          <el-date-picker
            v-model="formData.dateOfCorrection"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd"
          />
        </el-form-item> -->
            <el-form-item label="转正状态">
                <el-select v-model="formData.stateOfCorrection" placeholder="请选择" disabled>
                    <el-option
                        v-for="item in EmployeeEnum.stateOfCorrection"
                        :key="item.value"
                        :value="item.value"
                    />
                </el-select>
            </el-form-item>
            <el-form-item label="职级">
                <el-input v-model="formData.rank" />
            </el-form-item>
            <el-form-item label="转正评价">
                <el-input v-model="formData.correctionEvaluation" type="textarea" placeholder="1-300位字符" />
            </el-form-item>
            <el-form-item label="汇报对象">
                <el-select
                    v-model="formData.reportId"
                    filterable
                    placeholder="请选择"
                >
                    <el-option
                        v-for="item in depts"
                        :key="item.id"
                        :label="item.username"
                        :value="item.id"
                    />
                </el-select>
            </el-form-item>
            <el-form-item label="HRBP">
                <el-select
                    v-model="formData.hrbp"
                    filterable
                    placeholder="请选择"
                >
                    <el-option
                        v-for="item in depts"
                        :key="item.id"
                        :label="item.username"
                        :value="item.id"
                    />
                </el-select>
            </el-form-item>
            <el-form-item class="formInfo" label="调整司龄(天)">
                <el-input
                    v-model="formData.adjustmentAgedays"
                    type="number"
                    placeholder="请输入"
                />
            </el-form-item>
            <el-form-item label="首次参加工作时间">
                <el-date-picker
                    v-model="formData.workingTimeForTheFirstTime"
                    type="date"
                    placeholder="选择日期"
                    value-format="yyyy-MM-dd"
                />
            </el-form-item>
            <el-form-item label="调整工龄">
                <el-input
                    v-model="formData.adjustmentOfLengthOfService"
                    placeholder="0.00年"

                    disabled
                />
            </el-form-item>
        </div>
        <!-- 合同信息 -->
        <div class="block">
            <div class="title">合同信息</div>
            <el-form-item class="formInfo" label="首次合同开始时间">
                <el-date-picker
                    v-model="formData.initialContractStartTime"
                    type="date"
                    placeholder="选择日期"
                    value-format="yyyy-MM-dd"
                />
            </el-form-item>
            <el-form-item label="首次合同结束时间">
                <el-date-picker
                    v-model="formData.firstContractTerminationTime"
                    type="date"
                    placeholder="选择日期"
                    value-format="yyyy-MM-dd"
                />
            </el-form-item>
            <el-form-item label="现合同开始时间">
                <el-date-picker
                    v-model="formData.currentContractStartTime"
                    type="date"
                    placeholder="选择日期"
                    value-format="yyyy-MM-dd"
                />
            </el-form-item>
            <el-form-item label="现合同结束时间">
                <el-date-picker
                    v-model="formData.closingTimeOfCurrentContract	"
                    type="date"
                    placeholder="选择日期"
                    value-format="yyyy-MM-dd"
                />
            </el-form-item>
            <el-form-item label="合同期限">
                <el-select v-model="formData.contractPeriod" class="filter-item">
                    <el-option
                        v-for="item in EmployeeEnum.contractPeriod"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                    />
                </el-select>
            </el-form-item>
            <el-form-item label="续签次数">
                <el-select v-model="formData.renewalNumber" class="filter-item">
                    <el-option
                        v-for="item in EmployeeEnum.renewalCount"
                        :key="item.id"
                        :label="item.value"
                        :value="item.id"
                    />
                </el-select>
            </el-form-item>
        </div>
        <!-- 招聘信息 -->
        <div class="block">
            <div class="title">招聘信息</div>
            <el-form-item label="其他招聘渠道">
                <el-select v-model="formData.otherRecruitmentChannels" placeholder="请选择">
                    <el-option
                        v-for="item in EmployeeEnum.resumeSource"
                        :key="item.id"
                        :label="item.value"
                        :value="item.value"
                    />
                </el-select>
            </el-form-item>
            <el-form-item label="招聘渠道">
                <el-select v-model="formData.recruitmentChannels" placeholder="请选择">
                    <el-option
                        v-for="item in EmployeeEnum.resumeSource"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                    />
                </el-select>
            </el-form-item>
            <el-form-item label="社招/校招">
                <el-select v-model="formData.socialRecruitment" placeholder="请选择">
                    <el-option
                        v-for="item in EmployeeEnum.hireSourceType"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                    />
                </el-select>
            </el-form-item>
            <el-form-item label="推荐企业/人">
                <el-input v-model="formData.recommenderBusinessPeople" placeholder="请输入" class="infoPosition" />
            </el-form-item>
        </div>
        <!-- 从业信息 -->
        <el-row class="inline-info" type="flex" justify="center">
            <el-col :span="10" style="display: flex; justify-content: space-evenly;">
                <el-button type="primary" @click="saveJob">保存</el-button>
                <el-button @click="$router.back()">返回</el-button>
            </el-col>
        </el-row>
    </el-form>
</div>

</template>

<script>
import EmployeeEnum from '@/api/constant/employees'
import { getEmpJobDetailById, updateEmpJobDetailById, getEmployeeSimple } from '@/api/employees.js'
export default {
	data() {
		return {
			userId: this.$route.params.id,
			formData: {
				adjustmentAgedays: '', // 调整司龄天
				adjustmentOfLengthOfService: '', // 调整工龄天
				closingTimeOfCurrentContract: '', // 现合同结束时间
				companyId: '', // 公司ID
				contractDocuments: '', // 合同文件
				contractPeriod: '', // 合同期限
				correctionEvaluation: '', //  转正评价
				currentContractStartTime: '', // 现合同开始时间
				firstContractTerminationTime: '', // 首次合同结束时间
				hrbp: '', // HRBP
				initialContractStartTime: '', // 首次合同开始时间
				otherRecruitmentChannels: '', // 其他招聘渠道
				post: '', // 岗位
				rank: null, // 职级
				recommenderBusinessPeople: '', // 推荐企业人
				recruitmentChannels: '', // 招聘渠道
				renewalNumber: '', // 续签次数
				reportId: '', // 汇报对象
				reportName: null, // 汇报对象
				socialRecruitment: '', // 社招校招
				stateOfCorrection: '', // 转正状态
				taxableCity: '', // 纳税城市
				userId: '', // 员工ID
				workMailbox: '', // 工作邮箱
				workingCity: '', // 工作城市
				workingTimeForTheFirstTime: '' // 首次参加工作时间
			},
			EmployeeEnum,
			depts: []
		}
	},
	created() {
		this.getJobDetail(this.userId)
		this.getDepts()
	},
	methods: {
		/* 获取工作列表 */
		async getDepts() {
			const res = await getEmployeeSimple()
			this.depts = res
		},
		/* 获取岗位信息 */
		async getJobDetail(id) {
			const res = await getEmpJobDetailById(id)
			this.formData = res
			console.log(res)
		},
		/* 保存岗位信息 */
		async saveJob() {
			const res = await updateEmpJobDetailById(this.userId, this.formData)
			console.log(res)
			this.$message.success('保存岗位信息成功')
		}
	}
}
</script>

<style scoped lang="scss">
	.el-select{
		width: 100%;
	}
	.el-input{
		width: 100%;
	}
	.job-info{
		max-width: 1000px;
		margin: 0 auto;
		.title{
			color: #2784fb;
			font-weight: bold;
			font-size: 20px;
			margin: 20px 0;
		}
		.importantForm{
			.el-form-item{
				max-width: 500px;
			}
		}

		.detailInfo{
			margin-top: 30px;
		}
	}
</style>
